/*
 *      This program is free software; you can redistribute it and/or modify
 *      it under the terms of the GNU General Public License as published by
 *      the Free Software Foundation; either version 2 of the License, or
 *      (at your option) any later version.
 *      
 *      This program is distributed in the hope that it will be useful,
 *      but WITHOUT ANY WARRANTY; without even the implied warranty of
 *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *      GNU General Public License for more details.
 *      
 *      You should have received a copy of the GNU General Public License
 *      along with this program; if not, write to the Free Software
 *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 *      MA 02110-1301, USA.
 */

package test;

import java.util.*;
import java.lang.*;
import bgtp.*;

public class FilterTest
{
    public static void printRes(String name, boolean should, boolean really)
    {
	boolean tRes = should == really;

	System.out.println("["+tRes+"] '"+name+"': ("+should+") "+really);
	System.out.println("----------");
    }

    public static void runTest(String exp__, 
			       Filter inst,
			       TreeMap<String, String> v,
			       boolean bexp)
    {
	if(inst.make(exp__) == false)
	    {
		System.out.println("Filter construct fail");
	    }
	else
	    {
		printRes(exp__, bexp, inst.check(v));
	    }
    }

    public static void main(String[] args)
    {
	Filter flt = new Filter();
	String expr = "";
	TreeMap<String, String> val = new TreeMap<String, String>();
	boolean result;

	//case1
	val.put("abc","value001");
	expr = "abc = value001";
	runTest(expr, flt, val, true);

	//case2
	expr = "abc != value001";
	runTest(expr, flt, val, false);

	//case3
	val.put("abc2","value002");
	runTest("(abc = value001) & (abc2 = value002)",  flt, val, true);

	//case 4
	runTest("(abc = value001) | (abc2 = value003)",  flt, val, true);

	//case 5
	runTest("(abc = value001) | (abc1 = value002)",  flt, val, true);

	//case 6
	runTest("(abc = value001) | (abc1 = 'v*2')",  flt, val, true);

	//case 7
	runTest("abc ~ '.*'", flt, val, true);
    }
}
